package com.ycw.cs.service.hospital.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ycw.cs.api.entity.hospital.HospitalSet;
import com.ycw.cs.api.service.hospital.HospitalSetService;
import com.ycw.cs.service.hospital.mapper.HospitalSetMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {

    /**
     * 查询所有医院的信息(MyBatis-plus的方式)
     * @return
     */
    @Override
    public List<HospitalSet> findAllByPlus() {
         return baseMapper.selectList(null);
    }

    /**
     * 查询所有医院的信息(MyBatis的方式)
     * @return
     */
    @Override
    public List<HospitalSet> findAll() {
        return baseMapper.findAll(null);
    }

    /**
     * 分页查询医院的信息
     * @param page
     * @param hospitalSet
     * @return
     */
    @Override
    public Page<HospitalSet> selectPage(Page<HospitalSet> page, HospitalSet hospitalSet) {
        //构造查询条件
        QueryWrapper<HospitalSet> wrapper=new QueryWrapper<>();
        if(!StringUtils.isEmpty(hospitalSet.getHosname())){
            wrapper.like("hosname",hospitalSet.getHosname());
        }
        if(!StringUtils.isEmpty(hospitalSet.getHoscode())) {
            wrapper.eq("hoscode", hospitalSet.getHoscode());
        }
        Page<HospitalSet> hospitalSetPage = baseMapper.selectPage(page, wrapper);
        return hospitalSetPage;
    }


}
